$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'service/servicereceivegoods/list',
        datatype: "json",
        colModel: [			
			{ label: 'srgId', name: 'srgId', index: 'srg_id', width: 50, key: true },
			{ label: '关联售后id', name: 'srgSrId', index: 'srg_sr_id', width: 80 }, 			
			{ label: '收货状态（1.待审核2.待收货 3.待检测 4.待入库 5.已入库)', name: 'srgStatus', index: 'srg_status', width: 80 }, 			
			{ label: '收货单号', name: 'srgReceiveCode', index: 'srg_receive_code', width: 80 }, 			
			{ label: '收货时间', name: 'srgReceiveTime', index: 'srg_receive_time', width: 80 }, 			
			{ label: '收货人', name: 'srgReceiveName', index: 'srg_receive_name', width: 80 }, 			
			{ label: '商品id(sku)', name: 'srgProductId', index: 'srg_product_id', width: 80 }, 			
			{ label: '商品名称', name: 'srgGoodsName', index: 'srg_goods_name', width: 80 }, 			
			{ label: '商品数量', name: 'srgQuantity', index: 'srg_quantity', width: 80 }, 			
			{ label: '已签收数量', name: 'srgSignQuantity', index: 'srg_sign_quantity', width: 80 }, 			
			{ label: '检测人（员工id）', name: 'srgCheckName', index: 'srg_check_name', width: 80 }, 			
			{ label: '检测时间', name: 'srgCheckTime', index: 'srg_check_time', width: 80 }, 			
			{ label: '检测结果', name: 'srgCheckResult', index: 'srg_check_result', width: 80 }, 			
			{ label: '入库人（员工id）', name: 'srgInStockName', index: 'srg_in_stock_name', width: 80 }, 			
			{ label: '入库时间', name: 'srgInStockTime', index: 'srg_in_stock_time', width: 80 }, 			
			{ label: '入库仓库（仓库id）', name: 'srgStockId', index: 'srg_stock_id', width: 80 }, 			
			{ label: '伪删除标记（0正常 1删除）', name: 'srgDel', index: 'srg_del', width: 80 }, 			
			{ label: '更新人（员工id）', name: 'srgUpdateName', index: 'srg_update_name', width: 80 }, 			
			{ label: '更新时间', name: 'srgUpdateTime', index: 'srg_update_time', width: 80 }, 			
			{ label: '创建人（员工id）', name: 'srgCreateName', index: 'srg_create_name', width: 80 }, 			
			{ label: '创建时间', name: 'srgCreateTime', index: 'srg_create_time', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		serviceReceiveGoods: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.serviceReceiveGoods = {};
		},
		update: function (event) {
			var srgId = getSelectedRow();
			if(srgId == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(srgId)
		},
		saveOrUpdate: function (event) {
			var url = vm.serviceReceiveGoods.srgId == null ? "service/servicereceivegoods/save" : "service/servicereceivegoods/update";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                contentType: "application/json",
			    data: JSON.stringify(vm.serviceReceiveGoods),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var srgIds = getSelectedRows();
			if(srgIds == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "service/servicereceivegoods/delete",
                    contentType: "application/json",
				    data: JSON.stringify(srgIds),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(srgId){
			$.get(baseURL + "service/servicereceivegoods/info/"+srgId, function(r){
                vm.serviceReceiveGoods = r.serviceReceiveGoods;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});